

<?php

include('config.php');
$tbl_name = "artikelen";
$FileName = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME); //dit geeft de naam van de pagina terug, zonder .php erachter.




$max = 25; //amount of articles per page. change to what to want

$p = $_GET['p'];

if(empty($p))

{

$p = 1;

}

$limits = ($p - 1) * $max; 

//view the news article!

if(isset($_GET['act']) && $_GET['act'] == "view")

{

$id = $_GET['id'];

$sql = mysql_query("SELECT DISTINCT * FROM $tbl_name WHERE idartikelen = '$id'");
$r = mysql_fetch_array($sql);
$cat1 = $r['subcategory1'];
$cat2 = $r['subcategory2'];
$cat3 = $r['subcategory3'];
$beschrijving = $r['beschrijving'];
$afbeelding = $r['imagefilename'];
echo ("<img src='images/products/normal_$afbeelding'</img>");
echo ("Categorie: $cat1 ==> $cat2 ==> $cat3 <br>"); //hier de "category tree" in aanmaak
echo ("Beschrijving: $beschrijving"); //we beschrijven de handel
echo "<table border='1' bordercolor='#000000'>"; //begin van de tabel
$kopje_vorige = " "; //hiermee zorgen we ervoor dat als 2x achter elkaar hetzelfde kopje komt, alleen de eerste wordt weergegeven. Dit is de variabele om de vorige te onthouden.
while($r = mysql_fetch_array($sql))

{

$name2 = $r['name2'];

$name3 = $r['name3'];

$value = $r['value'];
if($name2 == $name3) { $name3 = " ";}
if($name2 == $kopje_vorige) {$name2 = " ";} else {$kopje_vorige = $name2;}

echo "<tr><td> $name2 </td><td> $name3  </td><td>$value</td>";

}
echo "</table>"; //tabel netjes afsluiten 
///////////////hier om iets aan je cart toe te voegen
echo"<form method='post'action='http://www.group3productions.info/cart/ShoppingCart.php'>
  <input name='SerialNum' type='hidden' value='$id' />
  <input name='cmd' type='hidden' id='cmd' value='1' /> 
  <input type='submit' name='Submit' value='Toevoegen aan wagentje' />
</form>";

//hier komen de gerelateerde artikelen
$related = "Gerelateerde producten:";
echo "<br /><br /><br />$related<br /><br />";
$relsql = mysql_query("SELECT distinct idartikelen, name, price, imagefilename, korting FROM artikelen WHERE subcategory1 = '$cat1' AND subcategory2 = '$cat2' AND subcategory3 = '$cat3' AND idartikelen <> '$id' ORDER BY rand() LIMIT 4");
$relresult = mysql_fetch_array($relsql) or die (mysql_error());
while($relresult=mysql_fetch_array($relsql))
{
 $relimg = $relresult['imagefilename'];
 $relid = $relresult['idartikelen'];
 $relname = $relresult['name'];
 
 $relprice = $relresult['price'];
 $korting= $r['korting'];
$korting=$korting/100;
$relprice = ($relprice-($relprice*$korting));
$relprice =  number_format($relprice, 2, ',', ' ');

 echo "<img src='images/products/thumb_$relimg'</img> <a href='artikelen.php?act=view&id=$relid'>$relname</a> $relprice <br /><br />";
}



} elseif(isset($_GET['act']) && $_GET['act'] == "cat"){
	
	$cat1 = $_GET['cat1'];
if(isset($_GET['cat2']))
{
	$cat2 = $_GET['cat2'];
	$sqlcat2 = " AND subcategory2='$cat2' "; 
}else{$sqlcat2="";}
if(isset($_GET['cat3']))
{
	$cat3 = $_GET['cat3'];
	$sqlcat3 = " AND subcategory3='$cat3' "; 
}else{$sqlcat3="";}
	
$query = "select name, price, name2, name3, value, description, imagefilename, idartikelen, korting FROM $tbl_name WHERE subcategory1='$cat1' $sqlcat2 $sqlcat3 GROUP BY idartikelen  LIMIT ".$limits.",$max";
$sql = mysql_query($query) or die(mysql_error());
 //nutteloze dingen er nog uit halen!!!

//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT( DISTINCT idartikelen) AS tot FROM $tbl_name WHERE subcategory1='$cat1'$sqlcat2 $sqlcat3"),0); 	

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max); 

//the table


echo "<table border='3' width='550px;'><tr><td>cart</td><td>naam</td><td>prijs</td><td>thumb</td></tr>";

while($r = mysql_fetch_array($sql))

{

$id = $r['idartikelen'];

$name = $r['name'];
$korting= $r['korting'];
$korting=$korting/100;
$price= $r['price'];
$price = ($price-($price*$korting));


$price =  number_format($price, 2, ',', ' ');
$img = $r['imagefilename'];
echo "<tr><td><form method='post'action='http://www.group3productions.info/cart/ShoppingCart.php'>
  <input name='SerialNum' type='hidden' value='$id' />
  <input name='cmd' type='hidden' id='cmd' value='1' /> 
  <input type='image' src='images/cart.png' width='25px' />
</form></td><td><a href='$FileName.php?act=view&id=$id'>$name</a></td><td>&euro; $price</td><td><img src='images/products/thumb_$img'</img></tr>";
//echo "<tr><td>$id</td><td><a href='$FileName.php?act=view&id=$id'>$name</a></td><td>&euro; $price</td><td><img src='images/products/thumb_$img'</img></tr>";

}

//close up the table

echo "</table>";
for($i = 1; $i <= $totalpages; $i++){ 

//this is the pagination link
if(isset($_GET['cat1'])){$cat1 = $_GET['cat1'];$cat1link="&cat1=$cat1";}
if(isset($_GET['cat2'])){$cat2 = $_GET['cat2'];$cat2link="&cat2=$cat2";}
if(isset($_GET['cat3'])){$cat3 = $_GET['cat3'];$cat3link="&cat3=$cat3";}
echo "<a href='$FileName.php?p=$i$cat1link$cat2link$cat3link&act=cat'>$i</a>|";
if($i%25==0)
echo"<br>";
}

}else{



//view all the news articles in rows

$sql = mysql_query("select name, price, name2, name3, value, description, imagefilename, korting, idartikelen FROM $tbl_name GROUP BY idartikelen LIMIT ".$limits.",$max") or die(mysql_error()); //nutteloze dingen er nog uit halen!!!

//the total rows in the table

$totalres = mysql_result(mysql_query("SELECT COUNT( DISTINCT idartikelen) AS tot FROM $tbl_name"),0);	

//the total number of pages (calculated result), math stuff...

$totalpages = ceil($totalres / $max); 

//the table

echo "<table border='3' width='550px;'>";

while($r = mysql_fetch_array($sql))

{

$id = $r['idartikelen'];
$name = $r['name'];
$korting= $r['korting'];
$korting=$korting/100;
$price= $r['price'];
$price = ($price-($price*$korting));
$price =  number_format($price, 2, ',', ' ');
$img = $r['imagefilename'];

echo "<tr><td><form method='post'action='http://www.group3productions.info/cart/ShoppingCart.php'>
  <input name='SerialNum' type='hidden' value='$id' />
  <input name='cmd' type='hidden' id='cmd' value='1' /> 
  <input type='image' src='images/cart.png' width='25px' />
</form></td><td><a href='$FileName.php?act=view&id=$id'>$name</a></td><td>&euro; $price</td><td><img src='images/products/thumb_$img'</img></tr>";

//echo "<tr><td>$id</td><td><a href='$FileName.php?act=view&id=$id'>$name</a></td><td>&euro; $price</td><td><img src='images/products/thumb_$img'</img></tr>";

}

//close up the table

echo "</table>";




if($totalpages >100)$totalpages=100;
for($i = 1; $i <= $totalpages; $i++){ 
//this is the pagination link

echo "<a href='$FileName.php?p=$i'>$i</a>|";
if($i%25==0)
echo"<br>";
}

}



?>